/**
 * Class Homework #2. This class is called "Vector" and stores elements.
 * 
 * @author (Greg Shevach) 
 * @version (v1.0 9/20/11)
 */

import java.util.*;


public class Vector<E> {
 
  ArrayList arrayList;  //Making an arraylist variable
  int capacity;
  
  public Vector() {
    capacity = 10;
    arrayList = new ArrayList(10);
  }
  
  public Vector(int initialCapacity) {
    capacity = initialCapacity;
    arrayList = new ArrayList(initialCapacity);
  }
  
  public void add(E element) { //Adds an element to end of vector
    arrayList.add(element);
  }
 
  public int capacity() { //Returns capacity of the arraylist
    return capacity;
  }
  
  public void clear() {  //Clears the arraylist
    arrayList.clear();
  }
  
  public E elementAt(int index) {  //Returns element at specified index
    return (E)arrayList.get(index);
  }
  
  public E firstElement() {
    return (E)arrayList.get(0);
  }
  
  public E get(int index) {
    return (E)arrayList.get(index);
  }
  
  public boolean isEmpty() {  //Is arrarylist empty or not?
    return arrayList.isEmpty();
  }
  
  public E lastElement() {
    return (E)arrayList.get(arrayList.size() - 1);
  }
  
  public E remove(int index) {                          //Which element do you want to remove from the arraylist?
    E o = (E)arrayList.get(index);                      //Goes and gets element at given index
    arrayList.remove(index);                            //Removes element
    return o;                                           //Returns element you just removed
  } 
  
  public void removeAllElements() {  //Clears the arraylist
    arrayList.clear();
  }
  
  public int size() {
    return arrayList.size();
  }
  
  public void trimToSize() {  //Trims the capacity to the current size
    capacity = arrayList.size();
    arrayList.trimToSize();
  }
}
